import { hasToken } from '@/utils/storage'
import { Navigate, useLocation } from 'react-router-dom'
// 路由拦截
export default function AuthRoute({ children }) {
  // 记录登录前的组件的路由地址,方便登录成功回到当前路由对应的页面
  const location = useLocation()
  const pathname = location.pathname
 // console.log(hasToken());
  // 做登录校验
  if (!hasToken()) {
    return (
      <Navigate
        to="/login"
        state={{
          from: pathname,
        }}
      ></Navigate>
    )
  }
  return children
}
